package Generics;

import java.util.ArrayList;
import java.util.Objects;

public class GenericsDemo5 {
    public static void main(String[] args) {
        ArrayList<Animal> catlist=new ArrayList<>();
        catlist.add(new Cat());
        method(catlist);

        ArrayList<Animal> doglist=new ArrayList<>();
        doglist.add(new Dog());
        method(doglist);

    }
    public static void method(ArrayList<? extends Animal> list){
        for(Object o:list){
            Animal a1=(Animal) o;
            a1.work();
        }
    }
}
abstract class Animal{
    private String name;
    private int age;
    public Animal(){

    }
    public abstract void work();



    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
class Cat extends Animal{
    @Override
    public void work(){
        System.out.println("猫吃鱼");
    }
}

class Dog extends Animal{
    @Override
    public void work(){
        System.out.println("狗吃肉");
    }
}